(function () {
  new Vue({
    el: '#turnoverManagement',
    data() {
      return {
        currentPage: 1,
        limit: ['10'],
        totalPage: 0 ,
        totalCount: 0 ,
        pageLimits: [{name: '10', code: '10'}, {name: '15', code: '15'}, {name: '20', code: '20'}],
        keyword: '',
        turnover_date_begin: '',
        turnover_date_end: '',
        customer_id: '',
				customer_id_arr: [],
        contract_id: '',
        contract_id_arr: [],
        project_id_s: '',
        building_id_s: '',
        floor_id_s: '',
        unit_id_s: '',
        project_id_n: '',
        building_id_n: '',
        floor_id_n: '',
        unit_id_n: '',
        turnover_date: '',
        turnover_amount_n: '',
        memo_n: '',
        //****录入参数****/
        entryTurnover: {
          turnoverId: '',
          turnover_amount: '',
          memo: '',
        },
        isExtenseFlag: false, //展开与收起
        listMenu: [{ name: '待录入', code: 'WIPT', num: 0 }, { name: '已录入', code: 'YIPT', num: 0, }, { name: '已提交', code: 'YTJ', num: 0 }],
        selectedListMenuCode: [],
        projectList_n: [],//所有项目(新增)
        projectListIds: '',//所有项目ID
        buildingList_n: [], //所有楼栋（新增）
        floorList_n: [],//所有楼层（新增）
        unitList_n: [],//所有单元（新增）
        projectList_s: [],//所有项目（搜索）
        buildingList_s: [], //所有楼栋（搜索）
        floorList_s: [],//所有楼层（搜索）
        unitList_s: [],//所有单元（搜索）
        contractList: [],//合同列表(搜索)
        customerList: [],//客户列表（搜索）
        importFlag: false, //导入
        notThrough: false,
        detectionBtn: true,
        detection: false, //检测
        is500: false,
        through: false,
        srcUrl: '',
        isShowDownload: false,
        addFlag: false, //新增
        entryFlag: false, //录入
        columns: '',
        orders: '',
        StatuscountData: {},
        feedbackData: '', //校验反馈
        entryText: '',//录入或者修改营业额（弹出框表头文本）
        dateaccoard: false, //营业时间是否大于当前时间
        permissions: JSON.parse(localStorage.getItem('permissions')),
        configType: 'WZ', //默认完整WZ     JD简单，WZ完整，自定义配置PZ
        module: '#',
        headArr: [],
        sortTableTitle: [],
        isScroll: false,
        isShowTableLayer: false,
        dateTimeUpdate: [],
        isActiveCode: '#',
        tbTitleWidth: {},
        listObj: { turnoverInfoListPageVO: [] },
        HlValidator: '',
				projectId: [],
				buildingId: [],
				floorId: [],
				unitId: [],
        groupId:null,
        groupOneData:[],
        groupTwoData:[],
        groupThreeData:[],
        selectedGroupData:[],
      }
    },
    filters: {
      formatUndefined: function (item) {
        if (!item) return '--'
        if (typeof item == 'number') {
        	if (!isNaN(item) && item.toString().length == 13) {
        		return hlDateUtil.formatUTCDate(item, 'yyyy-MM-dd')
        	};
        }
        return item
      },
    },
    created() {
      hlSelectUi()
    },
    watch: {
      turnover_date() {
        this.checkData()
        this.addVerify()
      },
      project_id_n() {
        this.addVerify()
      },
      building_id_n() {
        this.addVerify()
      },
      floor_id_n() {
        this.addVerify()
      },
      unit_id_n() {
        this.addVerify()
      }
    },
    mounted() {
      this.getprojectData();
      this.initSortable();
      this.configTypeDt();
      this.getTurnoverResource();

      fileUpload('.upload-filess', uploadUrl, (src) => {
        if (src.json == undefined) return;
        if (!(src.json.name.indexOf('xls') > -1 || src.json.name.indexOf('xlsx') > -1)) {
          hl.toast('请上传正确的模板')
          return
        }

        this.srcUrl = src.json.url.substr(src.json.url.lastIndexOf('/') + 1);
        $('.filename-i').val(src.json.name)
      })

      this.HlValidator = new HlValidator()
    },
    methods: {
      selectMenuList(){
        this.currentPage = 1
        this.getTurnoverData()
      },
      openSearch() {
        if (this.isExtenseFlag == true) {
          this.isExtenseFlag = false;
          return false;
        }
        if (this.isExtenseFlag == false) {
          this.isExtenseFlag = true;
          return false;
        }
      },
			newProjectClick (arr) {
        this.projectId = [arr[0].code]
				this.selectProject(this.projectId[0],'s','project')
        this.selectedGroupData = []
        this.getGroupPrimaryData(arr)
			},
			newBuildingClick (arr) {
        this.buildingId = [arr[0].code]
				this.selectBuilding(this.buildingId[0],'s','building')
			},
			newFloorClick (arr) {
        this.floorId = [arr[0].code]
				this.selectFloor(this.floorId[0],'s','floor')
			},
			newUnitClick (arr) {
        this.unitId = [arr[0].code]
				this.selectUnit(this.unitId[0], 's','nuit')
			},
			newProjectClickn (arr) {
        this.projectId = [arr[0].code]
				this.selectProject(this.projectId[0],'n','project')
        this.getGroupPrimaryData(arr)
			},
			newBuildingClickn (arr) {
        this.buildingId = [arr[0].code]
				this.selectBuilding(this.buildingId[0],'n','building')
			},
			newFloorClickn (arr) {
        this.floorId = [arr[0].code]
				this.selectFloor(this.floorId[0],'n','floor')
			},
			newUnitClickn (arr) {
        this.unitId = [arr[0].code]
				this.selectUnit(this.unitId[0], 'n','nuit')
			},
      check() {
        setTimeout(() =>{
          if(this.entryFlag){
            this.HlValidator.add(this.entryTurnover.turnover_amount, [
              {
                rule: 'isPositiveNumber',
                msg: '请输入正确金额'
              }])
            var errorMsg = this.HlValidator.start()
            if (errorMsg != true) {
              hl.toast(errorMsg)
            }
          }
        },300)
      },
      getTurnoverData() {
        const self = this

        hlhttp.get({
          url: 'turnover/_search',
          data: {
            "keyword": self.keyword || '#',
            "turnover_date_begin": self.turnover_date_begin || '#',
            "turnover_date_end": self.turnover_date_end || '#',
            "customer_id": self.customer_id || '#',
            "contract_id": self.contract_id || '#',
            "project_id": self.projectId.length ? self.projectId[0] : self.project_id_s,
            "group_id": self.groupId || '#',
            "building_id": self.buildingId.length ? self.buildingId[0] : '#',
            "floor_id": self.floorId.length ? self.floorId[0] : '#',
            "unit_id": self.unitId.length ? self.unitId[0] : '#',
            "status_code": self.selectedListMenuCode.length ? self.selectedListMenuCode.join(',') : '#',
            "page": self.currentPage,
            "limit": self.limit[0],
            "columns": self.columns || '#',
            "orders": self.orders || '#',
          },
          success: function (res) {
            self.listObj = res
            self.totalCount = res.totalCount
            self.totalPage = res.totalPage
            self.getStatuscountData();
          }
        })
      },
      // 营业额管理列表数量统计（待录入数量、已录入数量、已提交数量 ）
      getStatuscountData() {
        let self = this
        hlhttp.get({
          url: 'turnover/_search/status_count',
          data: {
            "keyword": self.keyword || '#',
            "turnover_date_begin": self.turnover_date_begin || '#',
            "turnover_date_end": self.turnover_date_end || '#',
            "customer_id": self.customer_id || '#',
            "contract_id": self.contract_id || '#',
            "project_id": self.project_id_s || '#',
            "group_id": self.groupId || '#',
            "building_id": self.building_id_s || '#',
            "floor_id": self.floor_id_s || '#',
            "unit_id": self.unit_id_s || '#',
          },
          success: function (res) {
            self.listMenu[0]['num'] = res.wIPTcount
            self.listMenu[1]['num'] = res.yIPTcount
            self.listMenu[2]['num'] = res.yTJcount
          }
        })
      },
      // 营业额资源选择
      getTurnoverResource() {
        hlhttp.get({
          url: 'turnover/_resource',
          data: {
            "project_id": this.project_id_s || '#',
            "building_id": this.building_id_s || '#',
            "floor_id": this.floor_id_s || '#',
            "unit_id": this.unit_id_s || '#'
          },
          success: (res) => {
						if (!res.customerInfo) {res.customerInfo = []}
						if (!res.contractInfo) {res.contractInfo = []}
            this.contractList = hlArrayUtil.replaceData(res.contractInfo, [{key: 'contractInfo', rKey: 'name'}, {key: 'contractId', rKey: 'code'}]);
            this.customerList = hlArrayUtil.replaceData(res.customerInfo, [{key: 'customerName', rKey: 'name'}, {key: 'customerId', rKey: 'code'}]);
            this.customer_id = ''
            this.contract_id = ''
          }
        })
      },
      //获取项目
     getprojectData() {
      hlhttp.get({
        url: 'user/projects',
        success: (res) => {
          res = hlArrayUtil.removeRepeat(res, 'projectId')
          this.projectList_n = hlArrayUtil.replaceData(res, [{key: 'projectName', rKey: 'name'}, {key: 'projectId', rKey: 'code'}]);
          this.projectList_s = hlArrayUtil.replaceData(res, [{key: 'projectName', rKey: 'name'}, {key: 'projectId', rKey: 'code'}]);

          let arr = []
          res.map(item => arr.push(item.projectId))
          this.project_id_s = this.projectListIds = arr.join(',')
          this.getTurnoverData();
          this.getStatuscountData();
        }
      })
    },

      // 获取一级组合数据
      getGroupPrimaryData(data){
        const self = this
        self.projectId = [data[0].code]
        self.buildingId = []
        this.getGroupData().then(data => {
          self.groupOneData = hlArrayUtil.replaceData( data, [{key: 'id', rKey: 'code'}] );
        })
        self.getBuildingData()
      },
      // 选取一级组合数据
      selectOneGroup(res){
        const self = this
        this.groupId = res['cur']['code']
        this.getGroupData().then(data => {
          self.groupTwoData = hlArrayUtil.replaceData( data, [{key: 'id', rKey: 'code'}] )
          self.getBuildingData()
        })
      },
      // 选取二级组合数据
      selectTwoGroup(res){
        const self = this
        this.groupId = res['cur']['code']
        this.getGroupData().then(data => {
          self.groupThreeData = hlArrayUtil.replaceData( data, [{key: 'id', rKey: 'code'}] )
          self.getBuildingData()
        })
      },
      // 选取三级组合数据
      selectThreeGroup(res){
        this.groupId = res['cur']['code']
      },
      getGroupData(){
        const self = this
        return new Promise(resolve => {
          hlhttp.get({
            url:'project/grouping_info/_subclass',
            data:{'project_id':self.projectId[0] , 'grouping_id':self.groupId || '#' },
            success:function(data){
              resolve(data)
            }
          })
        })
      },
      //获取楼宇
      getBuildingData() {
        const self = this
        hlhttp.get({
          url: 'project/grouping/_building',
          data:{ project_id: self.projectId.length ? self.projectId[0] : '#'  , grouping_id:self.groupId || '#'},
          success: (res) => {
            res = res.filter(el => el.configState == 'Y')
            self.buildingList_n = hlArrayUtil.replaceData(res, [{key: 'buildingId', rKey: 'code'}]);
            self.buildingList_s = hlArrayUtil.replaceData(res, [{key: 'buildingId', rKey: 'code'}]);
          }
        })
      },
      //获取楼层
      getfloorData() {
        const self = this
        hlhttp.get({
          url: 'building/floors',
          data: { project_id:self.projectId[0] , building_id:self.buildingId[0] },
          success: (res) => {
            self.floorList_n = hlArrayUtil.replaceData(res, [{key: 'floorName', rKey: 'name'}, {key: 'floorId', rKey: 'code'}]);
            self.floorList_s = hlArrayUtil.replaceData(res, [{key: 'floorName', rKey: 'name'}, {key: 'floorId', rKey: 'code'}]);
          }
        })
      },
      //获取单元
      getunitData(id) {
        const self = this
        hlhttp.get({
          url: 'floor/units',
          data: { project_id:self.projectId[0] , building_id:self.buildingId[0] , floor_id:self.floorId[0] },
          success: (res) => {
            self.unitList_n = hlArrayUtil.replaceData(res, [{key: 'unitName', rKey: 'name'}, {key: 'unitId', rKey: 'code'}]);
            self.unitList_s = hlArrayUtil.replaceData(res, [{key: 'unitName', rKey: 'name'}, {key: 'unitId', rKey: 'code'}]);
          }
        })
      },
      // 检查日期是否超过今天
      checkData() {
        if(!this.turnover_date) return
        let now = new Date()
        let nowTimestamp = now.getTime()
        let selectDate = new Date(this.turnover_date + ' ' + '00:00:00')
        let selectDateTimestamp = selectDate.getTime()
        if (nowTimestamp > selectDateTimestamp) {
          this.dateaccoard = true
          this.addVerify();
        } else {
          this.dateaccoard = false
          this.feedbackData = ''
          hl.toast('营业日期须小于或等于当前日期');
          return
        }
      },
      // 重置筛选状态
      resetStatus() {
        this.selectedListMenuCode = []
        this.currentPage = 1
        this.getTurnoverData()
      },
      //新增按钮
      newAdd() {
        this.addFlag = true
        this.project_id_n = ''
        this.building_id_n = ''
        this.floor_id_n = ''
        this.unit_id_n = ''
        this.feedbackData = ''
        this.turnover_date = ''
        this.turnover_amount_n = ''
				this.projectId = []
				this.buildingId = []
				this.floorId = []
				this.unitId = []
        this.memo_n = ''
      },
      // 选中客户Id
      selectCustomerId(arr) {
        this.customer_id = arr[0].code
				this.customer_id_arr = [arr[0].code]
      },
      // 选中合同Id
      selectContractId(arr) {
        this.contract_id = arr[0].code
				this.contract_id_arr = [arr[0].code]
      },
      //选中项目(n为新增，s为搜索)
      selectProject(id, type, local) {
				this.buildingId = []
				this.floorId = []
				this.unitId = []
				this.customer_id_arr = []
				this.contract_id_arr = []

        if (type == 'n') {
          this.project_id_n = id
          this.building_id_n = '',
          this.floor_id_n = '',
          this.unit_id_n = '',
          this.buildingList_n = []
          this.floorList_n = []
          this.unitList_n = []
          this.getBuildingData()
        }

        if (type == 's'){
          this.project_id_s = id
          this.building_id_s = '',
          this.floor_id_s = '',
          this.unit_id_s = '',
          this.getBuildingData()
          this.getTurnoverResource()
        }

      },
      //选中楼栋(n为新增，s为搜索)
      selectBuilding(id, type, local) {
				this.floorId = []
				this.unitId = []
				this.customer_id_arr = []
				this.contract_id_arr = []

        if (type == 'n') {
          this.building_id_n = id
          this.floor_id_n = '',
          this.unit_id_n = '',
          this.floorList_n = []
          this.unitList_n = []
          this.getfloorData()
        }

        if(type == 's'){
          this.building_id_s = id
          this.floor_id_s = '',
          this.unit_id_s = '',
					this.getfloorData()
          this.getTurnoverResource()
        }

      },
      //选中楼层(n为新增，s为搜索)
      selectFloor(id, type, local) {
				// this.buildingId = []
				// this.floorId = []
				this.customer_id_arr = []
				this.contract_id_arr = []
				this.unitId = []

        if (type == 'n') {
          this.floor_id_n = id
          this.unit_id_n = '',
          this.unitList_n = []
          this.getunitData()
        }

        if (type == 's') {
          this.floor_id_s = id
          this.unit_id_s = '',
					this.getunitData()
          this.getTurnoverResource()
        }

      },
      //选中单元(n为新增，s为搜索)
      selectUnit(id, type, local) {
				this.customer_id_arr = []
				this.contract_id_arr = []
        if (type == 'n') {
          this.unit_id_n = id
        }

        if (type == 's') {
          this.unit_id_s = id
          this.getTurnoverResource()
        }
      },
      // 新增营业额校验
      addVerify() {
        if (this.project_id_n && this.building_id_n && this.floor_id_n && this.unit_id_n && this.turnover_date && this.dateaccoard) {
          hlhttp.get({
            url: 'turnover/add_verify',
            data: {
              "project_id": this.project_id_n,
              "building_id": this.building_id_n,
              "floor_id": this.floor_id_n,
              "unit_id": this.unit_id_n,
              "turnover_date": this.turnover_date
            },
            success: (res) => {
              this.feedbackData = res
            }
          })
        }
      },
      // 确定新增营业额
      sureAddTurnover() {
        if (this.feedbackData.messageInfo != 'OK' && this.feedbackData.messageInfo != 'N') {
          return
        }
        if (!this.project_id_n) {
          hl.toast('请选择项目')
          return
        }
        if (!this.building_id_n) {
          hl.toast('请选择楼栋')
          return
        }
        if (!this.floor_id_n) {
          hl.toast('请选择楼层')
          return
        }
        if (!this.unit_id_n) {
          hl.toast('请选择单元')
          return
        }
        if (!this.turnover_date) {
          hl.toast('请选择营业日期')
          if (!this.dateaccoard) {
            hl.toast('营业日期须小于或等于当前日期');
            return
          }
          return
        }

        this.HlValidator.add(this.turnover_amount_n, [
          {
            rule: 'isEmpty',
            msg: '请输入金额'
          },
          {
            rule: 'isAmount',
            msg: '请输入正确金额'
          }])
        var errorMsg = this.HlValidator.start()
        if (errorMsg != true) {
          hl.toast(errorMsg)
          return false
        }
        var that = this

        if(this.feedbackData.messageInfo == 'OK'){
          hlhttp.post({
            url: 'turnover_info',
            data: {
              "project_id": this.project_id_n,
              "group_id": this.groupId || '#',
              "building_id": this.building_id_n,
              "floor_id": this.floor_id_n,
              "unit_id": this.unit_id_n,
              "customer_id": this.feedbackData.customerInfoPage.customerId || '#',
              "customer_name": this.feedbackData.customerInfoPage.customerName || '#',
              "customer_short_name": this.feedbackData.customerInfoPage.customerShortName || '#',
              "customer_lperson": this.feedbackData.customerInfoPage.customerLperson || '#',
              "customer_phone": this.feedbackData.customerInfoPage.customerPhone || '#',
              "contract_id": this.feedbackData.contractInfoPage.contractId || '#',
              "turnover_date": this.turnover_date,
              "turnover_amount": this.turnover_amount_n,
              "memo": this.memo_n || '#'
            },
            success: function (res) {
              hl.toast('添加成功')
              that.reset()
              that.addFlag = false
              that.getTurnoverData();

            }
          })
        }

        if(this.feedbackData.messageInfo == 'N'){
          hlhttp.post({
            url: 'turnover_info',
            data: {
              "project_id": this.project_id_n,
              "group_id": this.groupId || '#',
              "building_id": this.building_id_n,
              "floor_id": this.floor_id_n,
              "unit_id": this.unit_id_n,
              "customer_id":  '#',
              "customer_name":  '#',
              "customer_short_name":  '#',
              "customer_lperson": '#',
              "customer_phone":'#',
              "contract_id": '#',
              "turnover_date": this.turnover_date,
              "turnover_amount": this.turnover_amount_n,
              "memo": this.memo_n || '#'
            },
            success: function (res) {
              hl.toast('添加成功')
              that.reset()
              that.addFlag = false
              that.getTurnoverData();
            }
          })
        }

      },
      // 设置分页数量
      setMoreNum(arr) {
        this.limit = [arr[0].code]
        this.currentPage = 1
        this.getTurnoverData()
      },
      search() {
        this.currentPage = 1
        this.getTurnoverData();
      },
      //重置
      reset() {
        this.currentPage = 1
        this.keyword = ''
        this.columns = ''
        this.orders = ''
        this.turnover_date_begin = ''
        this.turnover_date_end = ''
        this.customer_id = ''
        this.contract_id = ''
        this.project_id_s = this.projectListIds

        this.building_id_s = ''
        this.floor_id_s = ''
        this.unit_id_s = ''
        this.buildingList_s = []
        this.floorList_s = []
        this.unitList_s = []
        this.contractList = []
        this.customerList = []
        this.selectedListMenuCode = []
				this.projectId = []
        this.groupId = null
				this.buildingId = []
				this.floorId = []
				this.unitId = []
				this.customer_id_arr = []
				this.contract_id_arr = []
        this.selectedGroupData = []
        this.isActiveCode = ''
        this.getTurnoverData();
      },
      //导入
      importExcl() {
        this.importFlag = true;
      },
      //关闭
      importExclClose() {
        this.importFlag = false;
        this.detection = false;
        this.notThrough = false;
        this.detectionBtn = true;
        this.through = false;
        this.srcUrl = '';
        $('.filename-i').val('')
      },
      //上传模板
      downloadxslc() {
        $('.upload-filess').trigger('click')
        this.detection = false;
        this.notThrough = false;
        this.detectionBtn = true;
        this.through = false;
        this.srcUrl = '';
        $('.filename-i').val('')
      },
      //检测
      detectionXslx() {
        if (!this.srcUrl) return;
        this.detection = true;
        this.detectionB = false;
        hlhttp.put({
          baseUrl: exclUrl,
          url: 'resource/turnover_check ',
          data: { file_name: this.srcUrl },
          success: res => {
            if (res.code == 200) {
              this.detection = false;
              this.detectionBtn = false;
              this.notThrough = false;
              this.through = true;
            }
            if (res.code == 500) {
              this.detection = false;
              this.detectionBtn = false;
              this.notThrough = true;
              this.through = false;
              this.srcUrl = res.url;
              this.isShowDownload = true;
            }
          },
          error: res => {
            hl.toast(JSON.parse(res.responseText).msg)
            this.detection = false;
            this.detectionBtn = false;
            this.notThrough = true;
            this.through = false;
            this.isShowDownload = false;

          }
        })
      },
      //submit xslc
      submibXslc() {
        hlhttp.post({
          baseUrl: exclUrl,
          url: 'resource/turnover_upload_data',
          data: { file_name: this.srcUrl.substr(this.srcUrl.lastIndexOf('/') + 1) },
          success: () => {
            hl.toast('上传成功')
            this.getTurnoverData()
            this.importExclClose()
          }
        })
      },
      //录入按钮
      EntryBut(item) {
        this.entryFlag = true
        this.entryText = '录入'
        this.entryTurnover = {
          turnoverId: item.id,
          turnover_amount: '',
          memo: '',
        }
      },
      //修改按钮
      changeBut(item) {
        this.entryFlag = true
        this.entryText = '修改'
        this.entryTurnover = {
          turnoverId: item.id,
          turnover_amount: item.turnoverAmount,
          memo: item.memo ? item.memo : '',
        }
      },
      //录入/修改营业额
      sureEntryTurnover() {
        this.HlValidator.add(this.entryTurnover.turnover_amount, [
          {
            rule: 'isEmpty',
            msg: '请输入金额'
          },
          {
            rule: 'isAmount',
            msg: '请输入正确金额'
          }])
        var errorMsg = this.HlValidator.start()
        if (errorMsg != true) {
          hl.toast(errorMsg)
          return false
        }
        var that = this
        hlhttp.put({
          url: 'turnover_info',
          data: {
            "id": this.entryTurnover.turnoverId,
            "turnover_amount": this.entryTurnover.turnover_amount,
            "memo": this.entryTurnover.memo
          },
          success: function (res) {
            that.entryFlag = false
            that.getTurnoverData();
          }
        })
      },
      // 前往营业额详情
      goTodetail(id) {
        hlUrlUtil.goTo('turnoverDetail', { id: id, ddtab: true }, true)
      },
      // 穿透详情（合同/客户）
      throughFunc(id, type) {
        if (type == 'contract') {
          hlUrlUtil.goTo('contractNewDeatil', { 'id': id, 'proId': this.project_id_n, 'ddtab': true }, true)
        } else {
          hlUrlUtil.goTo('customerDetails', { 'id': id, 'ddtab': true }, true)
        }
      },
      //更新时间
      sortBySTTime(item) {
        if (this.dateTimeUpdate.indexOf(item.value) == -1) return
        this.isActiveCode = item.value;
        this.orders = this.orders == 'ASC' ? 'DESC' : 'ASC';
        this.columns = item.orderName
        this.getTurnoverData();

      },
      //获取自定义表头配置状态
      configTypeDt() {
        hlhttp.get({
          url: 'configure/customize_column_header/type',
          data: { module: 'HETN_YYGL' },
          success: (data) => {
            this.configType = data.configType;
            this.customizeHeaderDt()
          }
        })
      },
      //获取自定义表头配置信息
      customizeHeaderDt() {
        hlhttp.get({
          url: 'configure/customize_column_header',
          data: { module: 'HETN_YYGL' },
          success: (data) => {
            data.customConfigList.map(item => {
              item.seq = Number(item.seq)
              item.customSeq = Number(item.customSeq)
              item.isActive = 'N'
              if (item.orderFlag == 'Y') {
                this.dateTimeUpdate.push(item.value)
              }
            })

            if (this.configType == 'JD' || this.configType == 'WZ') {
              data.customConfigList = data.customConfigList.sort(hlArrayUtil.compareAsc('seq'))
            }
            if (this.configType == 'PZ') {
              data.customConfigList = data.customConfigList.sort(hlArrayUtil.compareAsc('customSeq'))
            }
            this.headArr = JSON.parse(JSON.stringify(data.customConfigList));
            this.sortTableTitle = JSON.parse(JSON.stringify(data.customConfigList));
            this.tbTitleWidthCalculation()
          }
        })
      },
      //宽度计算
      tbTitleWidthCalculation() {
        let w = 0, flag = false;
        this.headArr.map(item => {
          if (item.value == '序') {
            flag = true;
          }
        })
        w = this.headArr.length * 120 - 80;
        this.tbTitleWidth = { width: w + 'px' }
      },
      //弹窗显示
      showTableLayer() {
        this.isShowTableLayer = true;
      },
      //关闭自定义表头弹窗
      closeTableLayer() {
        this.isShowTableLayer = false;
      },
      //简单完整配置切换
      selectTableType(type) {
        this.configType = type;
        this.changeTableType(type)
        this.updateConfigType()
      },
      //更新自定义表头配置状态
      updateConfigType() {
        hlhttp.put({
          url: 'configure/customize_column_header/type',
          data: { module: 'HETN_YYGL', config_type: this.configType },
          success: () => {
            this.configTypeDt()
          }
        })
      },
      //改变头部
      changeTableType(type) {
        if (type == 'JD' || type == 'WZ') {
          this.headArr = this.headArr.sort(hlArrayUtil.compareAsc('seq'))
        }
        if (type == 'PZ') {
          this.headArr = this.headArr.sort(hlArrayUtil.compareAsc('customSeq'))
        }
        this.tbTitleWidthCalculation()
      },
      //显示某个自定义标题
      selectedTitleItem(i) {
        this.sortTableTitle[i].customShowFlag = 'Y'
      },
      //关闭某个自定义标题
      cancelSelectedTitleItem(i) {
        this.sortTableTitle[i].customShowFlag = 'N'
      },
      showhighLightTitleItem(el, i) {
        this.sortTableTitle[i].isActive = 'Y'
      },
      removehighLightTitleItem(el, i) {
        this.sortTableTitle[i].isActive = 'N'
      },
      //鼠标经过显示scroll
      showScroll() {
        this.isScroll = true;
      },
      //鼠标离开关闭scroll
      hideScroll() {
        this.isScroll = false;
      },
      // 确定提交自定义表格
      confirmSubmitTable() {
        let dataArr = [];

        this.sortTableTitle.map((item, index) => {
          dataArr.push({
            "base_flag": item.baseFlag,
            "seq": item.seq,
            "custom_show_flag": item.customShowFlag,
            "custom_seq": index,
            "custom_display_name": item.customDisplayName ? item.customDisplayName : '#',
            "dict_code": item.dictCode,
            "config_type": item.configType,
            "name": item.name,
            "value": item.value,
            "union_table_part": item.unionTablePart,
            flex: item.flex,
            style_width: item.styleWidth,
            order_flag: item.orderFlag,
            order_name: item.orderName
          })
        })
        hlhttp.put({
          url: 'configure/customize_column_header',
          data: {
            module: 'HETN_YYGL',
            custom_config: JSON.stringify(dataArr)
          },
          success: (data) => {
            hl.toast('操作成功')
            this.closeTableLayer()
            this.updateConfigType()
          }
        })
      },
      // 初始化拖动排序
      initSortable() {
        const self = this;
        const el = document.getElementById('sortableTable');
        Sortable.create(el, {
          draggable: 'ul',
          onEnd(evt) {
            const beginIndex = evt.oldIndex;
            const endIndex = evt.newIndex;
            const newArr = JSON.parse(JSON.stringify(self.sortTableTitle));
            newArr.splice(endIndex, 0, newArr.splice(beginIndex, 1)[0])
            self.sortTableTitle = [];
            self.$nextTick(() => {
              self.sortTableTitle = newArr
            })
          }
        })
      },
    },
  })
}())
